package com.atguigu.factory.bSimpleFactory.pizzaStore.order;

import com.atguigu.factory.bSimpleFactory.pizzaStore.pizza.CheesePizza;
import com.atguigu.factory.bSimpleFactory.pizzaStore.pizza.GreekPizza;
import com.atguigu.factory.bSimpleFactory.pizzaStore.pizza.PepperPizza;
import com.atguigu.factory.bSimpleFactory.pizzaStore.pizza.Pizza;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 简单工厂（用来生产pizza）
 * @create: 2022-01-18 22:49
 **/
public class SimpleFactory {
    /**
     * 方法 一
     * 根据orderType订购类型，返回一个pizza披萨对象
     * @param orderType 订购类型
     * @return 披萨对象
     */
    public Pizza createPizza(String orderType){
        Pizza pizza = null;
        if ("greek".equals(orderType)){
            pizza = new GreekPizza();
            pizza.setName("希腊披萨");
        }else if ("cheese".equals(orderType)){
            pizza = new CheesePizza();
            pizza.setName("奶酪披萨");
        }else if ("pepper".equals(orderType)){
            pizza = new PepperPizza();
            pizza.setName("胡椒披萨");
        }
        return pizza;
    }

    /**
     * 简单工厂模式也叫 静态工厂模式
     * 方法 二
     * 根据orderType订购类型，返回一个pizza披萨对象
     * @param orderType 订购类型
     * @return 披萨对象
     */
    public static Pizza createPizza2(String orderType){
        Pizza pizza = null;
        if ("greek".equals(orderType)){
            pizza = new GreekPizza();
            pizza.setName("希腊披萨");
        }else if ("cheese".equals(orderType)){
            pizza = new CheesePizza();
            pizza.setName("奶酪披萨");
        }else if ("pepper".equals(orderType)){
            pizza = new PepperPizza();
            pizza.setName("胡椒披萨");
        }
        return pizza;
    }
}
